CC "AdoScript" SET_CWD path:(sADOxxPathGeo) # AdoScript to calculate the route between two markers SETL nRouteObjID:(nCurrentObjID) CC "Modeling" GET_ACT_MODEL SETL nCurrentModelID:(modelid) CC "Core" GET_ATTR_VAL modelid:(nCurrentModelID) objid:(nRouteObjID) attrname:("Longitude (Start)") SETL nStartLong:(val) CC "Core" GET_ATTR_VAL modelid:(nCurrentModelID) objid:(nRouteObjID) attrname:("Latitude (Start)") SETL nStartLat:(val) CC "Core" GET_ATTR_VAL modelid:(nCurrentModelID) objid:(nRouteObjID) attrname:("Longitude (End)") SETL nEndLong:(val) CC "Core" GET_ATTR_VAL modelid:(nCurrentModelID) objid:(nRouteObjID) attrname:("Latitude (End)") SETL nEndLat:(val) CC "Core" GET_ATTR_VAL modelid:(nCurrentModelID) objid:(nRouteObjID) attrname:("Travel mode") SETL sTravelMode:(val) #get tempfilename for route information CC "AdoScript" GET_TEMP_FILENAME SETL sRouteJSONFile:(filename) SYSTEM ("download_route.bat \""+sTravelMode+"\" \""+sRouteJSONFile+"\" \"" + nStartLat+"\" \"" + nStartLong+"\" \"" + nEndLat+"\" \"" + nEndLong + "\" \"" +g_sProxyServer+ "\"") with-console-window CC "AdoScript" FREAD file:(sRouteJSONFile) SETL sRouteJSON:(text) SETL sRouteJSONNormalized:"" FOR sRouteJSONText in:(sRouteJSON) sep:("\n") { SETL sRouteJSONNormalized:(sRouteJSONNormalized + "\n" + sRouteJSONText.trim()) } # replacement steps to produce a line based feed for text search SETL sRouteJSONNormalized:(replall(sRouteJSONNormalized, "\n", "")) SETL sRouteJSONNormalized:(replall(sRouteJSONNormalized, "},{", "},\n{")) SETL sRouteJSONNormalized:(replall(sRouteJSONNormalized, "\"legs\" : \[", "\n\"legs\" : \[")) SETL sRouteJSONNormalized:(replall(sRouteJSONNormalized, "\"steps\" : \[", "\n\"steps\" : \[")) CC "AdoScript" FWRITE file:("e:\\json.json") text:(sRouteJSONNormalized) SETL counter:1 SETL sStepsBuffer:"" FOR sRouteJSONNormalizedLine in:(sRouteJSONNormalized) sep:"\n" { # leg line IF (counter = 2) { SETL sDistance:(copy (sRouteJSONNormalizedLine, search(sRouteJSONNormalizedLine, "\"distance\" : {\"text\" : \"", 0)+24, search(sRouteJSONNormalizedLine, "m", 0)-(search(sRouteJSONNormalizedLine, "\"distance\" : {\"text\" : \"", 0)+24)+1)) SETL sDuration:(copy (sRouteJSONNormalizedLine, search(sRouteJSONNormalizedLine, "\"duration\" : {\"text\" : \"", 0)+24, search(sRouteJSONNormalizedLine, "min", 0)-(search(sRouteJSONNormalizedLine, "\"duration\" : {\"text\" : \"", 0)+24)+3)) #copy (sRouteJSONNormalizedLine, search(sRouteJSONNormalizedLine, "\"distance\" : {\"text\" : \"", 0), 10 CC "Core" SET_ATTR_VAL modelid:(nCurrentModelID) objid:(nRouteObjID) attrname:("Distance") val:(sDistance) CC "Core" SET_ATTR_VAL modelid:(nCurrentModelID) objid:(nRouteObjID) attrname:("Duration") val:(sDuration) } IF (counter > 2) { SETL sStepCounter:(STR (counter-2)) SETL sTempStart:(copy (sRouteJSONNormalizedLine, search(sRouteJSONNormalizedLine, "\"start_location\" : {\"lat\" : ", 0)+27, -1)) SETL sStart:(copy (sTempStart, 0, search (sTempStart, "}", 0))) SETL sTempEnd:(copy (sRouteJSONNormalizedLine, search(sRouteJSONNormalizedLine, "\"end_location\" : {\"lat\" : ", 0)+26, -1)) SETL sEnd:(copy (sTempEnd, 0, search (sTempEnd, "}", 0))) SETL sDuration:(copy (sRouteJSONNormalizedLine, search(sRouteJSONNormalizedLine, "\"duration\" : {\"text\" : \"", 0)+24, search(sRouteJSONNormalizedLine, "min", 0)-(search(sRouteJSONNormalizedLine, "\"duration\" : {\"text\" : \"", 0)+24)+3)) SETL sDistance:(copy (sRouteJSONNormalizedLine, search(sRouteJSONNormalizedLine, "\"distance\" : {\"text\" : \"", 0)+24, search(sRouteJSONNormalizedLine, "m", 0)-(search(sRouteJSONNormalizedLine, "\"distance\" : {\"text\" : \"", 0)+24)+1)) SETL sStep:("Step: " + sStepCounter+";Start:"+replall(sStart, "\"lng\" : ", "")+";End:"+replall(sEnd, "\"lng\" : ", "")+";Duration:"+sDuration+";Distance:"+sDistance) SETL sStepsBuffer:(tokunion(sStepsBuffer, sStep, "\n")) } SETL counter:(counter +1) } CC "Core" SET_ATTR_VAL modelid:(nCurrentModelID) objid:(nRouteObjID) attrname:("Steps") val:(sStepsBuffer) IF (bUpdateAll != 1) { CC "AdoScript" INFOBOX ("The route information has been updated successfully!") }